package com.ygo.feihua;


import android.app.*;
import android.content.*;
import android.content.pm.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import com.bumptech.glide.*;
import com.msk86.ygoroid.newutils.*;
import com.qnw.CardGroupManagement.*;
import com.xiaomi.channel.commonutils.logger.*;
import com.xiaomi.mipush.sdk.*;
import com.ygo.feihua.Management.*;
import com.ygo.feihua.util.*;
import com.yuyh.library.imgsel.*;
import com.yuyh.library.imgsel.common.*;
import java.io.*;

/**
 * @date 2016-2-24
 * TODO 闪屏界面，根据指定时间进行跳转
 */
public class SplashActivity extends Activity {

	//定时跳转的秒数
	//private static final long DELAY_TIME = 1500L;
	//DialogUtils du;
	String path=Gongju.PATH_OURYGO;
	
	private String TAG="SplashActivity";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0){
			finish();
			return;
		}
		
		
		new Thread(new Runnable(){

				@Override
				public void run()
				{
					Looper.prepare();
					initSdk();	
					startMain();
					Looper.loop();
				/*if(!SharedPreferenceUtil.getKgSpDialog()){
						Looper.prepare();
						
						Looper.loop();
					}else{
						han.sendEmptyMessage(0);
					}
					*/
					// TODO: Implement this method
				}
			}).start();
		}
		
	Handler han=new Handler(){

		@Override
		public void handleMessage(Message msg)
		{
			// TODO: Implement this method
			super.handleMessage(msg);
			switch(msg.what){
				case 0:
					DialogUtils du=DialogUtils.getdx(SplashActivity.this);
					View[] v=du.dialogt(true,"责任声明","[我们的游戏王]由于功能所需将每5分钟上传一次用户的位置信息,并将其与用户名,最后上传时间一并显示在“地图”功能中\n乃是否同意呢？");
					Button b1=(Button) v[0];
					Button b2=(Button) v[1];

					b1.setText("拒绝！");
					b2.setText("同意~");
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								finish();
								// TODO: Implement this method
							}
						});
					b2.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								SharedPreferenceUtil.getShareKaiguan().edit().putBoolean("spmz",false).commit();
								initSdk();
								startMain();
								// TODO: Implement this method
							}
						});
					break;
				
			}
		}
		
	};
		
	private void initSdk(){	
		SdkInitManagement sm=SdkInitManagement.getDx();
		sm.initAllSdk();
		
	}
	
	//跳转到主界面
	public void startMain(){
		//获取应用的启动次数
		int sc=SharedPreferenceUtil.getAppStartTimes();
		//自增一
		sc++;
		SharedPreferenceUtil.getShareRecord().edit().putInt("StartTimes",sc).commit();
		InItClass();

		fileCreate();
		CgmaZhuye.getType();
		
		
		startActivity(new Intent(SplashActivity.this,CeHua.class));
		finish();
	}
	
	private void InItClass()
	{
		// 自定义图片加载器
		ISNav.getInstance().init(new ImageLoader() {
				@Override
				public void displayImage(Context context, String path, ImageView imageView) {
					Glide.with(context).load(path).into(imageView);
				}
			});

		// TODO: Implement this method
	}



	public final  String[] OURYGO_File=new String[]{
		path+"image/.nomedia"
	};

	public final  String[] OURYGO_DIRECTORY=new String[]{
		path
		,path+"主题/"
		,path+"image/"
		,Gongju.PATH_EZ_MANAGEMENT
		,path+"Log/"
		,path+"download/"
		,path+"image/touxiang/"
		,path+"image/bc/"
		,path+"image/hc/"
		,Gongju.PATH_EZ_MANAGEMENT+"type/"
		,Gongju.PATH_EZ_MANAGEMENT+"archive/"
		,Gongju.PATH_EZ_MANAGEMENT+"ydk_fenxiang/"	
	};

	//检查各种文件和文件夹
	private void fileCreate(){
		for(String s:OURYGO_DIRECTORY){
			Gongju.directoryCreate(s);
		}
		for(String s:OURYGO_File){
			try
			{
				Gongju.fileCreate(s);
			}catch (IOException e){

			}
		}
		
		File ff=new File(path+"lflist.conf");
		if(!ff.exists()||Gongju.getIsNewVersion()){
			try
			{
				Gongju.copyAssets("lflist.conf", path);
			}catch (IOException e){

			}
		}

		//如果数据库路径中不存在数据库则把路径改为默认路径
		if(!new File(SharedPreferenceUtil.getCdbpath()).exists()){
			SharedPreferences sh=SharedPreferenceUtil.getSharePath();
			sh.edit().putString("cdbpath",Gongju.PATH_EZ_MANAGEMENT+"cards.cdb").commit();
		}
		//调整数据库
		//File fff=new File(Gongju.PATH_EZ_MANAGEMENT+"cards2.cdb");
		//卡片数据库
		File fff1=new File(Gongju.PATH_EZ_MANAGEMENT+"cards.cdb");
		if(/*!fff.exists()||*/!fff1.exists()||Gongju.getIsNewVersion()||fff1.length()<10*1024){
			try
			{
				//Gongju.copyAssets("cards2.cdb", Gongju.PATH_EZ_MANAGEMENT);
				Gongju.copyAssets("cards.cdb", Gongju.PATH_EZ_MANAGEMENT);
			}catch (IOException e){

			}		
		}


		//战队提示列表
		File ff1=new File(Gongju.PATH_OURYGO+"TeamList.txt");
		if (!ff1.exists()||Gongju.getIsNewVersion())
		{
			try
			{
				Gongju.copyAssets("TeamList.txt", Gongju.PATH_OURYGO);
			}catch (IOException e){

			}

		}
	}
	
	
}
